﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VTQuery.Net.Print;

namespace WindowsFormsTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }




        private void Form1_Load(object sender, EventArgs e)
        {
            IList<Formtest> list = new List<Formtest>();
            for (int i = 0; i <= 10; i++)
            {
                Formtest Info = new Formtest();
                Info.ID = (i + 1).ToString();
                Info.Name = "Name" + i;
                list.Add(Info);
            }
            dataGridView1.DataSource = new TQuery.Net.Generic.IListSort<Formtest>(list);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            PrintTest();
        }

        #region  打印
        /// <summary>
        /// 打印
        /// </summary>
        public static void PrintTest()
        {
            TablePrintDocument doc = new TablePrintDocument();
            doc.ColumnWidth = new int[] { 350, 350 };
            //doc.TitleMarginLeft = 300;
            doc.Title = "标题";
            doc.SubTitle = string.Format(@"打印日期：{0}",
                                         DateTime.Now.ToString("yyyy年M月d日"));
            doc.SubTitleMarginLeft = 40;
            Pen pen = new Pen(Color.Black);
            pen.Width = 1;
            doc.BorderPen = pen;

            List<TablePrintCell> cells = new List<TablePrintCell>();
            int i = 0;
            const int BigHeight = 40;

            string content00 = "打印1：123";
            TablePrintCell cell00 = new TablePrintCell(0, i, content00);
            cell00.Height = BigHeight;
            cells.Add(cell00);

            string content01 = "打印2：345";
            TablePrintCell cell01 = new TablePrintCell(1, 1, i, i, content01);
            cell01.Height = BigHeight;
            cells.Add(cell01);
            i++;

            string content40 = "备注：dec";
            TablePrintCell cell40 = new TablePrintCell(0, 1, i, i, content40);
            cell40.Height = BigHeight;
            cells.Add(cell40);
            i++;

            TablePrintCell cell61 = new TablePrintCell(0, 1, i, i, "说明：", 160);
            cell61.Height = BigHeight * 6;
            cells.Add(cell61);
            i++;

            string printer = "123";
            TablePrintCell cellSign = new TablePrintCell(0, 1, i, i,
                                                         string.Format("制单人1：{0}制单人2：{0}制单人3：{0}制单人4：{0}", "            "));
            cellSign.Height = BigHeight * 2;
            cells.Add(cellSign);
            doc.Cells = cells;

#if DEBUG
            doc.Preview();
#else
			doc.Print();
#endif
        }
        #endregion
    }
    public class Formtest
    {
        public string ID { get; set; }
        public string Name { get; set; }
    }
}
